package com.sysu.ooad.action;

import java.io.InputStream;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.Action;

@Component
@Scope("prototype")
public class DownloadHomeworkAction extends CommonAction {
	
	private String filename;
	private String uploadDir;
	
	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getUploadDir() {
		return uploadDir;
	}

	public void setUploadDir(String uploadDir) {
		this.uploadDir = uploadDir;
	}

	public InputStream getInputStream() throws Exception {
		return ServletActionContext.getServletContext().getResourceAsStream(uploadDir + "/" + filename);
	}

	@Override
	public String execute() throws Exception {
		return Action.SUCCESS;
	}
	
}
